/**
 * 
 */
package org.pump.client.type;

import java.util.HashMap;
import java.util.Map;

import org.pump.client.codec.TableMapEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author liudong03
 *
 */


public class MysqlType {
	private static final Logger mylog = LoggerFactory.getLogger(TableMapEvent.class);
		static Map<Short,Short> typemap = new HashMap<Short,Short>();
		public static final int MYSQL_TYPE_DECIMAL = 0;
		public static final int MYSQL_TYPE_TINY = 1;
		public static final int MYSQL_TYPE_SHORT = 2;
		public static final int MYSQL_TYPE_LONG = 3;
		public static final int MYSQL_TYPE_FLOAT = 4;
		public static final int MYSQL_TYPE_DOUBLE = 5;
		public static final int MYSQL_TYPE_NULL = 6;
		public static final int MYSQL_TYPE_TIMESTAMP = 7;
		public static final int MYSQL_TYPE_LONGLONG = 8;
		public static final int MYSQL_TYPE_INT24 = 9;
		public static final int MYSQL_TYPE_DATE = 10;
		public static final int MYSQL_TYPE_TIME = 11;
		public static final int MYSQL_TYPE_DATETIME = 12;
		public static final int MYSQL_TYPE_YEAR = 13;
		public static final int MYSQL_TYPE_NEWDATE = 14;
		public static final int MYSQL_TYPE_VARCHAR = 15;
		public static final int MYSQL_TYPE_BIT = 16;
		public static final int MYSQL_TYPE_NEWDECIMAL = 246;
		public static final int MYSQL_TYPE_ENUM = 247;
		public static final int MYSQL_TYPE_SET = 248;
		public static final int MYSQL_TYPE_TINY_BLOB = 249;
		public static final int MYSQL_TYPE_MEDIUM_BLOB = 250;
		public static final int MYSQL_TYPE_LONG_BLOB = 251;
		public static final int MYSQL_TYPE_BLOB = 252;
		public static final int MYSQL_TYPE_VAR_STRING = 253;
		public static final int MYSQL_TYPE_STRING = 254;
		public static final int MYSQL_TYPE_GEOMETRY = 255;
		static String[] desc = {
			"decimal",
			"tiny",
			"short",
			"long",
			"float",
			"double",
			"null",
			"timestamp",
			"longlong",
			"int24",
			"date",
			"time",
			"datetime",
			"year",
			"newdate",
			"varchar",
			"bit",
			"new decimal",
			"enum",
			"set",
			"tiny blob",
			"medium blob",
			"long blob",
			"var string",
			"string",
			"geometry"
		};
		static short[] metasize = {
				0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,0,1,2,2,1
			};
		static{
			short[] id = {
					0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,246,247,248,249,250,251,252,253,254,255
				};
			
			int sz = id.length;
			for(short i = 0; i < sz ; i++)
			{
				Short curid = new Short(id[i]);
				Short curpos = new Short(i);
				typemap.put(curid, curpos);
			}
		}
		
		public static Short getpos(short id)
		{
			return typemap.get(new Short(id));
		}
		
		public static short getMetasize(short id)
		{
			Short cur = getpos(id);
			if(cur == null)
			{
				mylog.error("the parm is is not exist");
				return -1;
			}
			return metasize[cur.shortValue()];
		}
		
		public static String getDesc(short id)
		{
			Short cur = getpos(id);
			if(cur == null)
			{
				mylog.error("the parm is is not exist");
				return null;
			}
			return desc[cur.shortValue()];
		}

}
